package com.pudu.mydemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pudu.mydemo.view.MapBuildView;
import com.pudu.pdrobot.App;
import com.pudutech.pdrobot.R;

/**
 * Created by guiliu on 2016/7/14.
 */
public class MapFragment extends Fragment {

    MapBuildView myview;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_map,container,false);

        String strMap = App.getInstance().getApplicationMapData();
        if(strMap != null) Log.i("aaaa", strMap);

        myview = (MapBuildView) view.findViewById(R.id.myview);
        myview.SetWorkMode(4);
        myview.LoadMap(strMap);

        return view;
    }

    int nMapIndex = 0;
    public void showNextMLines()
    {
        int nSize = myview.GetMapSize();
        nMapIndex++;
        if( nSize < (nMapIndex+1)){
            nMapIndex = 0;
            myview.showMapByIndex(nMapIndex);
        }else
        {
            myview.showMapByIndex(nMapIndex);
        }

        myview.SetWorkMode(4);
    }

    public void showPreviousMLines()
    {
        int nSize = myview.GetMapSize();
        nMapIndex--;
        if( nMapIndex < 0){
            nMapIndex = myview.GetMapSize() -1;
            myview.showMapByIndex(nMapIndex);
        }else
        {
            myview.showMapByIndex(nMapIndex);
        }

        myview.SetWorkMode(4);
    }

    public int getCurrentMapLines()
    {
        return nMapIndex;
    }
}
